<?php

namespace backend\controllers;

use Yii;
use common\models\meeting\Meetingenroll;
use common\models\meeting\MeetingenrollSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use common\models\auth\Auth;

/**
 * MeetingenrollController implements the CRUD actions for Meetingenroll model.
 */
class CodeController extends Controller
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all Meetingenroll models.
     * @return mixed
     */
    public function actionZy()
    {
        if(empty(\Yii::$app->user->identity))
        {
               $this->redirect(['site/login']);
        }
        if(yii::$app->user->id)
        {
            $user_id = yii::$app->user->id;
            $qiandao = Auth::findBySql("select parent from auth_item_child where child='meeting/qiandao'")->asArray()->all();
            $userinfo = Yii::$app->db->createCommand("SELECT a.user_id FROM auth_assignment as a  left join auth_item_child as b on b.parent=a.item_name WHERE a.user_id=" .$user_id. " and b.child='code/yz'")->queryOne();
            if($userinfo['user_id'])
            {
                $pingzheng= Yii::$app->request->get()["code"];
                $userinfo = Yii::$app->db->createCommand("update meetingenroll set status=1 where code=".$pingzheng)->execute();
                if($userinfo>0)
                {
                    echo '签到成功';
                }
                else
                {
                    echo "请出示正确的凭证码";
                } 
            }
            else
            {
                echo '无权限';
            }
        }
    }



}
